<?php (!defined('IN_SYSTEM') || !defined('ADMIN_PRE')) && exit('Access Denied!');?>
{admintemplate header}
<div class="box">
	<div class="heading">
	<h1>地区列表</h1>
	<div class="buttons">
	<a href="{url admin.php?m=region}" class="fr">地区列表</a>
	</div>
	</div>
	<div class="main">

		<div class="search">
			<form name="search" id="search" method="post" action="?m=region">
			<input type="hidden" id="rid" value="{$id}" name="rid" class="searchid"/>
				<fieldset>
					<legend>选择地区</legend>
						选择地区：{php $i=0;;}
						{loop $datast $d}
						<select onchange="region(this,{$i});" id="level{$i}" name="level{$i}">
						<option value="">-请选择-</option>
						{loop $d $p}
						<option value="{$p['rid']}" {if $p['rid']==$selected[$i]}selected{/if}>{$p['region']}</option>
						{/loop}
						</select>
						{php $i++;}
						{/loop}
						
				</fieldset>
			</form>
		</div>

		<form name="update" method="post" action="?m=region">
			<input type="hidden" id="regionsubmit" value="true" name="regionsubmit" />
			<input type="hidden" id="rid" value="{$id}" name="rid" />
			<table cellspacing="0" class="list" id="list">
			<thead>
				<tr>
					<td>地区名称</td>
					<td width="120">操作</td>
				</tr>
				</thead>
				<tbody>
				{loop $datas $v}
				<tr id="tr{$v['rid']}"><td><input type="text" value="{$v['region']}" name="region[{$v['rid']}]" size="50" class="txt" /></td><td><a onclick="deleterow({$v['rid']});return false;" href="javascript:;">删除</a></td></tr>
				{/loop}
				</tbody>
			</table>
			<div style="padding:10px;"><a onclick="addrow();return false;" href="javascript:;">添加</a></div>
			<div style="text-align:center;"><input type="submit" class="button" value="保存" /> </div>
		</form>
		<script type="text/javascript">
		function addrow(){
			$("#list").append('<tr><td ><input type="text" name="regionnew[]"  size="50" /></td><td></td></tr>');
		}
		function deleterow(id){
			$("#tr"+id).empty();
		}
		function region(obj,le){
			if($(obj).val()<1 && le>0 && $("#level"+(le-1)).val() >0){
				$(".searchid").val($("#level"+(le-1)).val());
			}else{
				$(".searchid").val($(obj).val());
			}
			$('#search').submit();
		}
		</script>
	</div>
</div>
{admintemplate footer}